package com.example.crm.controller;

import com.example.crm.entity.CustomerCategory;
import com.example.crm.service.CustomerCategoryService;
import com.example.crm.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户分类控制器
 */
@RestController
@RequestMapping("/api/customer/category")
public class CustomerCategoryController {

    @Autowired
    private CustomerCategoryService customerCategoryService;

    /**
     * 获取所有客户分类
     */
    @GetMapping("/list")
    public Result<List<CustomerCategory>> listAllCategories() {
        List<CustomerCategory> categories = customerCategoryService.listAllCategories();
        return Result.success(categories);
    }

    /**
     * 新增客户分类
     */
    @PostMapping("/add")
    public Result<Boolean> addCategory(@RequestBody CustomerCategory category) {
        boolean result = customerCategoryService.save(category);
        return Result.success(result);
    }

    /**
     * 更新客户分类
     */
    @PostMapping("/update")
    public Result<Boolean> updateCategory(@RequestBody CustomerCategory category) {
        boolean result = customerCategoryService.updateById(category);
        return Result.success(result);
    }

    /**
     * 删除客户分类
     */
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteCategory(@PathVariable Long id) {
        boolean result = customerCategoryService.removeById(id);
        return Result.success(result);
    }
} 